package drive.Service.ServiceFormat;

import com.google.gson.Gson;
import drive.Mapper.ImageMapper;
import drive.Model.Image;
import drive.Service.ServiceInterface.ImageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ImageServiceA implements ImageService {

    @Autowired
    private ImageMapper imageMapper;

    private Gson gson = new Gson();

    @Override
    public String findAll() {
        List<Image> list = imageMapper.findAll();
        return gson.toJson(list);
    }

    @Override
    public String findByImageID(Integer imageID) {
        Image image = imageMapper.findByImageID(imageID);
        return gson.toJson(image);
    }

    @Override
    public String findByArticleID(Integer articleID) {
        List<Image> list = imageMapper.findByArticleID(articleID);
        return gson.toJson(list);
    }

    @Override
    public String add(Image image) {
        int result = imageMapper.add(image);
        return "图片添加成功";
    }

    @Override
    public String update(Image image) {
        int result = imageMapper.update(image);
        return "图片更新成功";
    }

    @Override
    public String delete(Integer imageID) {
        int result = imageMapper.delete(imageID);
        return "图片删除成功";
    }
}